package test;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class MyArticlePage extends Utils {
    public static String url = "http://127.0.0.1:58080/index.html";
    public static ForumListPage forumListPage;
    public static WebDriverWait wait;

    public MyArticlePage() {
        super(url);
        forumListPage = new ForumListPage();
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    }

    public void MyArticle() {
        // 进入个人中心
        driver.get("http://127.0.0.1:58080/index.html");
        forumListPage.checkMyArticles();
        List<WebElement> elements = driver.findElements(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong"));
        if (!elements.isEmpty()) {
            WebElement webElement = elements.get(0);
            webElement.click();
            // 检查新页面的元素
            driver.findElement(By.cssSelector("#details_article_title"));
            driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div:nth-child(2) > h3"));
            driver.findElement(By.cssSelector("#details_article_createTime"));
            driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div.col-auto.d-none.d-md-inline > ul"));
            driver.findElement(By.cssSelector("#details_article_content_title"));
        } else {
            System.out.println("不存在帖子");
        }
    }
}
